package cc.orange.mainView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import cc.orange.BuildConfig;
import cc.orange.R;
import cc.orange.base.BaseActivity;
import cc.orange.databinding.ActivityLoginBinding;
import cc.orange.entity.IsLoginsEntity;
import cc.orange.entity.LoginPostEntity;
import cc.orange.entity.LoginPswPostEntity;
import cc.orange.entity.LoginsEntity;
import cc.orange.entity.MoABEntity;
import cc.orange.entity.MsgLoginUI3Entity;
import cc.orange.entity.UpdataUserPostEntity;
import cc.orange.entity.WxInfoEntity;
import cc.orange.http.ApiService;
import cc.orange.utils.ClicksSpans;
import cc.orange.utils.ScreenUtils;
import cc.orange.utils.WxLogUtil;
import cc.orange.utils.ZXToastUtil;
import cc.orange.utils.popup.PopupPhonelView;
import demo.smart.access.xutlis.util.ZXAppUtil;
import demo.smart.access.xutlis.util.ZXDeviceUtil;
import demo.smart.access.xutlis.util.ZXFormatCheckUtil;
import demo.smart.access.xutlis.util.ZXSharedPrefUtil;
import okhttp3.MediaType;
import okhttp3.RequestBody;

import android.Manifest;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
//import com.tendcloud.tenddata.TalkingDataGender;
//import com.tendcloud.tenddata.TalkingDataProfile;
//import com.tendcloud.tenddata.TalkingDataProfileType;
//import com.tendcloud.tenddata.TalkingDataSDK;
import com.xcheng.retrofit.Call;
import com.xcheng.retrofit.DefaultCallback;
import com.xcheng.retrofit.HttpError;
import com.xcheng.retrofit.RetrofitFactory;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class LoginActivity extends BaseActivity implements View.OnClickListener{

    private ActivityLoginBinding binding;
    private int type_clicks;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_login);
        EventBus.getDefault().register(this);
        initViews();
    }

    private void initViews() {
        RelativeLayout.LayoutParams pp = new RelativeLayout.
                LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ScreenUtils.getStatusBarHeight(LoginActivity.this));
        binding.loginTitle.setLayoutParams(pp);

        binding.loginTxt9.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        binding.loginTxt9.getPaint().setAntiAlias(true);//抗锯齿
        binding.loginRel5.setOnClickListener(this);
        binding.loginTxt9.setOnClickListener(this);
        binding.loginTxt1.setOnClickListener(this);
        binding.loginTxt2.setOnClickListener(this);
        binding.loginImg2Cicl.setOnClickListener(this);
        binding.loginTxt8.setOnClickListener(this);
        binding.loginTxt17.setOnClickListener(this);
        binding.loginImg1.setOnClickListener(this);
        binding.loginImg2.setOnClickListener(this);
        binding.loginEdit6.setOnClickListener(this);

        String s = "<font color=\"#666666\">登录即同意" +
                "<font ><a href= "+ BuildConfig.WEBS_URL1+">《用户服务协议》</a ></font>" +
                "和<font ><a href="+BuildConfig.WEBS_URL2+">《隐私权政策》</a ></font></font>";
        binding.loginText1.setText(getClickableHtml(this,s));
        //这一句很重要，否则ClickableSpan内的onClick方法将无法触发！！ color="#F48337"
        binding.loginText1.setMovementMethod(LinkMovementMethod.getInstance());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.login_txt9://账号登录切换
                binding.loginRel4.setVisibility(View.GONE);
                binding.loginRel1.setVisibility(View.VISIBLE);
                binding.loginRel6.setVisibility(View.GONE);
                binding.loginTxt1.setVisibility(View.VISIBLE);
                binding.loginTxt2.setVisibility(View.INVISIBLE);
                break;
            case R.id.login_rel5://微信登录
                if(type_clicks == 1) {
//                    WxLogUtil.loginWX();
                    getLogin(""+System.currentTimeMillis(),"用户"+System.currentTimeMillis(),
                            "img_1","1");
                }else{
                    ZXToastUtil.showToast("请先了解并同意用户协议");
                }
                break;
            case R.id.login_txt1://上一步
                if( binding.loginRel4.getVisibility() == View.VISIBLE){
                    finish();
                }else  if( binding.loginRel1.getVisibility() == View.VISIBLE){
                    binding.loginRel4.setVisibility(View.VISIBLE);
                    binding.loginRel1.setVisibility(View.GONE);
                    binding.loginRel6.setVisibility(View.GONE);
                    binding.loginTxt1.setVisibility(View.INVISIBLE);
                    binding.loginTxt2.setVisibility(View.INVISIBLE);

                    binding.loginsRelClick1.setVisibility(View.VISIBLE);
                }else  if( binding.loginRel6.getVisibility() == View.VISIBLE){
                    binding.loginRel4.setVisibility(View.VISIBLE);
                    binding.loginRel1.setVisibility(View.GONE);
                    binding.loginRel6.setVisibility(View.GONE);

                    binding.loginTxt1.setVisibility(View.INVISIBLE);
                    binding.loginTxt2.setVisibility(View.INVISIBLE);

                    binding.loginsRelClick1.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.login_txt2://下一步
                if( binding.loginRel1.getVisibility() == View.VISIBLE){
                    binding.loginRel6.setVisibility(View.VISIBLE);
                    binding.loginRel1.setVisibility(View.GONE);
                    binding.loginRel4.setVisibility(View.GONE);
                    binding.loginTxt1.setVisibility(View.VISIBLE);
                    binding.loginTxt2.setVisibility(View.INVISIBLE);

                    binding.loginsRelClick1.setVisibility(View.GONE);
                }
                break;
            case R.id.login_img2_cicl://点击同意
                if(type_clicks == 0){
                    type_clicks = 1;
                    binding.loginImg1Cicl.setVisibility(View.VISIBLE);
                    binding.loginImg3.setVisibility(View.GONE);
                }else{
                    type_clicks = 0;
                    binding.loginImg1Cicl.setVisibility(View.GONE);
                    binding.loginImg3.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.login_txt8://账号登录按钮
                if(type_clicks == 1) {
                    String trim = binding.loginEdit1.getText().toString().trim();
                    String trim2 = binding.loginEdit2.getText().toString().trim();
                    if(TextUtils.isEmpty(trim) || TextUtils.isEmpty(trim2)){
                        ZXToastUtil.showToast("请填写账号密码");
                    }else if(!ZXFormatCheckUtil.isPhoneNum(trim)){
                        ZXToastUtil.showToast("请输入正确手机号");
                    }else {
                        userLogin(trim,trim2);
                        binding.loginsRelClick1.setVisibility(View.GONE);
                    }
                }else{
                    ZXToastUtil.showToast("请先了解并同意用户协议");
                }
                break;
            case R.id.login_txt17://设置 信息按钮
                if(checkMsg()){
                    int types = -1;
                    if(binding.loginImg11.getVisibility() == View.VISIBLE){
                        types = 0;
                    }
                    if(binding.loginImg21.getVisibility() == View.VISIBLE){
                        types = 1;
                    }
                    updateUser(""+types,binding.loginEdit4.getText().toString().trim(),
                            binding.loginEdit6.getText().toString().trim(),binding.loginEdit3.getText().toString().trim());
                }

                break;
            case R.id.login_img1://男
                ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                ss.putString("url_hr","img_1");
                    binding.loginImg21.setVisibility(View.VISIBLE);
                    binding.loginImg11.setVisibility(View.GONE);
                break;
            case R.id.login_img2://女
                ZXSharedPrefUtil ss1 = new ZXSharedPrefUtil();
                ss1.putString("url_hr","img_0");
                binding.loginImg11.setVisibility(View.VISIBLE);
                binding.loginImg21.setVisibility(View.GONE);
                break;
            case R.id.login_edit6:
                getIpAddresDetail();
//                initNes();
                break;
        }
    }

    private boolean checkMsg() {
        if(TextUtils.isEmpty(binding.loginEdit3.getText().toString().trim())){
            ZXToastUtil.showToast("请填写昵称");
            return false;
        }else if(TextUtils.isEmpty(binding.loginEdit4.getText().toString().trim())){
            ZXToastUtil.showToast("请填写年龄");
            return false;
        }else if(TextUtils.isEmpty(binding.loginEdit6.getText().toString().trim()) ||
                binding.loginEdit6.getText().toString().trim().contains("定位")){
            ZXToastUtil.showToast("请填写地址");
            return false;
        }else if(binding.loginImg11.getVisibility() == View.GONE && binding.loginImg21.getVisibility() == View.GONE ){
            ZXToastUtil.showToast("请选择性别");
            return false;
        }
        return true;
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getLogisnMsg(WxInfoEntity wxInfoEntity){
        if(wxInfoEntity.getSex() == 0){
            getLogin(wxInfoEntity.getOpenid(),wxInfoEntity.getNickname(),
                    wxInfoEntity.getHeadimgurl(),wxInfoEntity.getSex() == 0 ? "1":"0");
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getLogisnMsgUI3(MsgLoginUI3Entity entity){
        if(entity.isShowUI3()){
            binding.loginRel4.setVisibility(View.GONE);
            binding.loginRel1.setVisibility(View.GONE);
            binding.loginRel6.setVisibility(View.VISIBLE);
            binding.loginTxt1.setVisibility(View.VISIBLE);
            binding.loginTxt2.setVisibility(View.INVISIBLE);

            getIpAddresDetail();
        }else{
            finish();
        }
    }

    private void getLogin(String openid, String nickname, String headimgurl, String sex) {
        LoginPostEntity entitys = new LoginPostEntity(openid,nickname,sex,headimgurl);
        Gson gss = new Gson();
        String s = gss.toJson(entitys);
        RequestBody requestBody1 = RequestBody.create(MediaType.parse("application/json"), s.toString());

        RetrofitFactory.create(ApiService.class)
                .login(requestBody1)
                .enqueue(new DefaultCallback<LoginsEntity>() {
                    @Override
                    public void onStart(Call<LoginsEntity> call) {
                        showLoading_base(LoginActivity.this);
                    }

                    @Override
                    public void onError(Call<LoginsEntity> call, HttpError error) {
                        cancelLoading();
                    }

                    @Override
                    public void onSuccess(Call<LoginsEntity> call, LoginsEntity baseEntity) {
                        cancelLoading();
                        if(baseEntity.getCode() == 0){
                            ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                            ss.putString("token_hr",baseEntity.getData());
                            ss.putBool("isLogin_hr",true);
                            ss.putString("name_hr",nickname);
                            ss.putString("openid_hr",openid);
                            ss.putString("url_hr",headimgurl);
                            ZXToastUtil.showToast("登录成功");
                            EventBus.getDefault().post(new IsLoginsEntity(true));

                            binding.loginEdit3.setText(nickname);
                            binding.loginsRelClick1.setVisibility(View.GONE);
//                            TalkingDataProfile profile = TalkingDataProfile.createProfile();
//                            profile.setName(nickname);
//                            profile.setType(TalkingDataProfileType.WEIXIN);
//                            profile.setGender(sex.equals("0") ? TalkingDataGender.MALE : TalkingDataGender.FEMALE);
//                            TalkingDataSDK.onLogin(openid,profile);

                        }else{
                            ZXToastUtil.showToast(baseEntity.getMsg());
                        }
                    }
                });
    }

    private void userLogin(String nick, String psw) {
        LoginPswPostEntity entitys = new LoginPswPostEntity(nick,psw);
        Gson gss = new Gson();
        String s = gss.toJson(entitys);
        RequestBody requestBody1 = RequestBody.create(MediaType.parse("application/json"), s.toString());

        RetrofitFactory.create(ApiService.class)
                .userLogin(requestBody1)
                .enqueue(new DefaultCallback<LoginsEntity>() {
                    @Override
                    public void onStart(Call<LoginsEntity> call) {
                        showLoading_base(LoginActivity.this);
                    }

                    @Override
                    public void onError(Call<LoginsEntity> call, HttpError error) {
                        cancelLoading();
                    }

                    @Override
                    public void onSuccess(Call<LoginsEntity> call, LoginsEntity baseEntity) {
                        cancelLoading();
                        if(baseEntity.getCode() == 0){
                            ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                            ss.putString("token_hr",baseEntity.getData());
                            ss.putBool("isLogin_hr",true);
                            ZXToastUtil.showToast("登录成功");
                            EventBus.getDefault().post(new IsLoginsEntity(true));



//                            TalkingDataProfile profile = TalkingDataProfile.createProfile();
//                            profile.setName(nick);
//                            profile.setType(TalkingDataProfileType.WEIXIN);
//                            profile.setGender(TalkingDataGender.MALE);
//                            TalkingDataSDK.onLogin(nick,profile);
                        }else{
                            if(baseEntity.getMsg().contains("此账号已经被注册")){
                                    PopupPhonelView.showPopupwindow(LoginActivity.this, binding.loginEdit1, new PopupPhonelView.PopuStatus() {
                                        @Override
                                        public void popupShow() {

                                        }

                                        @Override
                                        public void popupDismissCancle2(String se1) {
                                            binding.loginEdit1.setText("");
                                           binding.loginEdit2.setText("");
                                        }
                                    });
                            }
                            ZXToastUtil.showToast(baseEntity.getMsg());
                        }
                    }
                });
    }

    private void updateUser(String sex, String age,String address,String name) {
        UpdataUserPostEntity entitys = new UpdataUserPostEntity();
        entitys.setAge(age);
        entitys.setAddress(address);
        entitys.setSex(sex);
        entitys.setName(name);
//        ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
//        String url_hr = ss.getString("url_hr", "");
//        if(TextUtils.isEmpty(url_hr)){
        entitys.setHeadPhoto(sex.equals("1")? "img_1" : "img_0");
//        }else{
//            entitys.setHeadPhoto(url_hr);
//        }
        Gson gss = new Gson();
        String s = gss.toJson(entitys);
        RequestBody requestBody1 = RequestBody.create(MediaType.parse("application/json"), s.toString());

        RetrofitFactory.create(ApiService.class)
                .updateUser(getTokens(),requestBody1)
                .enqueue(new DefaultCallback<LoginsEntity>() {
                    @Override
                    public void onStart(Call<LoginsEntity> call) {
                        showLoading_base(LoginActivity.this);
                    }

                    @Override
                    public void onError(Call<LoginsEntity> call, HttpError error) {
                        cancelLoading();
                    }

                    @Override
                    public void onSuccess(Call<LoginsEntity> call, LoginsEntity baseEntity) {
                        cancelLoading();
                        if(baseEntity.getCode() == 0){
                            ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                            ss.putBool("isLogin_hr",true);
                            ss.putString("name_hr",name);
                            ss.putString("url_addres",address);
                            ss.putString("url_sex",sex);
                            ss.putString("url_age",age);
                            EventBus.getDefault().post(new IsLoginsEntity(true));
                            finish();
                        }else{
                            ZXToastUtil.showToast(baseEntity.getMsg());
                        }
                    }
                });
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if( binding.loginRel6.getVisibility() == View.VISIBLE){
//            initNes();
            getIpAddresDetail();
        }
//        TalkingDataSDK.onPageBegin(this, getLocalClassName());
    }

    @Override
    protected void onPause() {
        super.onPause();
//        TalkingDataSDK.onPageEnd(this, getLocalClassName());
    }

    /**
     * 格式化超链接文本内容并设置点击处理
     * */
    public static CharSequence getClickableHtml(Context context, String html) {
        Spanned spannedHtml = Html.fromHtml(html);
        SpannableStringBuilder clickableHtmlBuilder = new SpannableStringBuilder(spannedHtml);
        URLSpan[] urls = clickableHtmlBuilder.getSpans(0, spannedHtml.length(), URLSpan.class);
        for(final URLSpan span : urls) {
            setLinkClickable(context,clickableHtmlBuilder, span);
        }
        return clickableHtmlBuilder;
    }

    /**
     * 设置点击超链接对应的处理内容
     * */
    public static void setLinkClickable(final Context context, final SpannableStringBuilder clickableHtmlBuilder, final URLSpan urlSpan) {
        int start = clickableHtmlBuilder.getSpanStart(urlSpan);
        int end = clickableHtmlBuilder.getSpanEnd(urlSpan);
        int flags = clickableHtmlBuilder.getSpanFlags(urlSpan);
        ClicksSpans clickableSpan = new ClicksSpans() {
            @Override
            public void onClick(View view) {
                if(urlSpan.getURL().contains("yonghu")){//隐私政策
                    WebViewActivity.openH5Activity(context,"隐私政策", BuildConfig.WEBS_URL2);
                }else if(urlSpan.getURL().contains("xieyi")){
                    WebViewActivity.openH5Activity(context,"服务协议",BuildConfig.WEBS_URL1);
                }
            }
        };
        //实际使用过程中，可根据需要清空之前的span，防止出现重复调用的情况
        clickableHtmlBuilder.setSpan(clickableSpan, start, end, flags);
    }


    private static final String[] ACTIVITY_LOCATION_PERMISSION = {Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION};

    private void initNes() {

        int get2 = ContextCompat.checkSelfPermission(this, ACTIVITY_LOCATION_PERMISSION[0]);
        int get3 = ContextCompat.checkSelfPermission(this, ACTIVITY_LOCATION_PERMISSION[1]);
        if(get2 != PackageManager.PERMISSION_GRANTED && get3 != PackageManager.PERMISSION_GRANTED){
            ActivityCompat.requestPermissions(this, ACTIVITY_LOCATION_PERMISSION, 322);
        }else{
            initLocations();
        }

    }

    //声明AMapLocationClient类对象
    public AMapLocationClient mLocationClient = null;
    //声明定位回调监听器
    public AMapLocationListener mLocationListener;
    //声明AMapLocationClientOption对象
    public AMapLocationClientOption mLocationOption = null;
    //初始化AMapLocationClientOption对象
    private void initLocations() {

        //初始化定位
        try {
            mLocationListener= new AMapLocationListener() {
                @Override
                public void onLocationChanged(AMapLocation amapLocation) {
                    if (amapLocation != null) {
                        if (amapLocation.getErrorCode() == 0) {
//                            amapLocation.getLatitude();//获取纬度
//                            amapLocation.getLongitude();//获取经度
//                            amapLocation.getAccuracy();//获取精度信息
//                            amapLocation.getAddress();//地址，如果option中设置isNeedAddress为false，则没有此结果，网络定位结果中会有地址信息，GPS定位不返回地址信息。
//                            amapLocation.getCountry();//国家信息
//                            amapLocation.getProvince();//省信息
//                            amapLocation.getCity();//城市信息
//                            amapLocation.getDistrict();//城区信息

                            Log.e("---->locat","address:"
                                    + amapLocation.getAddress() + ", getCity:"
                                    + amapLocation.getCity()+ ", getProvince:"
                                    + amapLocation.getProvince()+ ", getDistrict:"
                                    + amapLocation.getDistrict());
                             binding.loginEdit6.setText(""+amapLocation.getCity());
                             ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                             ss.putString("url_addres",""+amapLocation.getCity());
                        }else {
                            //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
                            Log.e("---->AmapError","location Error, ErrCode:"
                                    + amapLocation.getErrorCode() + ", errInfo:"
                                    + amapLocation.getErrorInfo());
                            ZXToastUtil.showToast("定位失败，请检查相应权限");
                            binding.loginEdit6.setText("北京");
                            ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                            ss.putString("url_addres","北京");
                        }
                    }
                }
            };
            mLocationClient = new AMapLocationClient(this);
            mLocationClient.setLocationListener(mLocationListener);


            mLocationOption = new AMapLocationClientOption();
//设置定位模式为AMapLocationMode.Hight_Accuracy，高精度模式。
            mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
            mLocationOption.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
            //获取最近3s内精度最高的一次定位结果：
//设置setOnceLocationLatest(boolean b)接口为true，启动定位时SDK会返回最近3s内精度最高的一次定位结果。如果设置其为true，setOnceLocation(boolean b)接口也会被设置为true，反之不会，默认为false。
            mLocationOption.setOnceLocationLatest(true);
            //设置是否返回地址信息（默认返回地址信息）
            mLocationOption.setNeedAddress(true);
            //关闭缓存机制
            mLocationOption.setLocationCacheEnable(false);

            mLocationClient.setLocationOption(mLocationOption);
            //设置场景模式后最好调用一次stop，再调用start以保证场景模式生效
            mLocationClient.stopLocation();
            mLocationClient.startLocation();

        } catch (Exception e) {
            e.printStackTrace();
        }
//设置定位回调监听

    }



    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if(requestCode == 322){
            if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
                //提示用户手动开启权限
                new AlertDialog.Builder(this)
                        .setTitle("定位权限")
                        .setMessage("定位权限不可用")
                        .setPositiveButton("立即开启", (dialog12, which) -> {
                            // 跳转到应用设置界面
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", getPackageName(), null);
                            intent.setData(uri);
                            startActivityForResult(intent, 123);
                        })
                        .setNegativeButton("取消", (dialog1, which) -> {
                            Toast.makeText(getApplicationContext(), "没有获得权限，定位功能无法使用！", Toast.LENGTH_SHORT).show();
                        }).setCancelable(false).show();
            }else {
                initLocations();
            }
        }
    }



    private void getIpAddresDetail(){
        RetrofitFactory.create(ApiService.class)
                .getIpAddresDetail(getTokens(),BuildConfig.APP_CHANNEL,
                        BuildConfig.AppNames,
                        ZXAppUtil.getPackageName())
                .enqueue(new DefaultCallback<MoABEntity>() {
                    @Override
                    public void onStart(Call<MoABEntity> call) {
                    }

                    @Override
                    public void onError(Call<MoABEntity> call, HttpError error) {
                        ZXToastUtil.showToast("定位失败，请重试");
//                       "北京"
//                        checkGStatus("0");
                        binding.loginEdit6.setText("北京");
                        ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                        ss.putString("url_addres","北京");
                    }

                    @Override
                    public void onSuccess(Call<MoABEntity> call, MoABEntity baseEntity) {
                        Log.v("---->okhttp",baseEntity.getData().toString());
//                        checkGStatus(baseEntity.getData().getPkgType());
                        binding.loginEdit6.setText(""+baseEntity.getData().getCity());
                        ZXSharedPrefUtil ss = new ZXSharedPrefUtil();
                        ss.putString("url_addres",""+baseEntity.getData().getCity());
                    }
                });
    }

}